<template>
  <!-- 对话框(添加 / 修改) -->
  <el-dialog
    title="临时调课"
    :visible.sync="show"
    width="35%"
    append-to-body
    :before-close="cancel"
    :close-on-click-modal="false"
  >
    <el-form
      ref="form"
      :model="form"
      :rules="rules"
      :inline="true"
      label-width="80px"
    >
      <el-form-item label="选择周期" prop="">
        <el-input></el-input>
      </el-form-item>
      <el-form-item label="选择星期" prop="">
        <el-input></el-input>
      </el-form-item>
      <el-form-item label="选择课时" prop="">
        <el-input></el-input>
      </el-form-item>

      <el-form-item label="调课原因" prop="">
        <el-input></el-input>
      </el-form-item>
    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { createClasses, updateClasses } from "@/api/collegebase/classes";
import Editor from "@/components/Editor";
import common from "@/api/collegebase/common";
export default {
  name: "ClassesEdit",
  components: {
    Editor,
  },
  data() {
    return {
      // 表单参数
      form: {
        classesId: "",
        professionId: "",
      },
      // 表单校验
      rules: {
        classesName: [
          { required: true, message: "请输入班级名称", trigger: "blur" },
        ],
        classesGrade: [
          { required: true, message: "请选择年级", trigger: "blur" },
        ],
        collegeId: [
          { required: true, message: "请选择学院", trigger: "blur" },
        ],
        departmentsId: [
          { required: true, message: "请选择系部", trigger: "blur" },
        ],
        professionId: [
          { required: true, message: "请选择专业", trigger: "blur" },
        ],
        openingTime: [
          { required: true, message: "请选择开班时间", trigger: "blur" },
        ],
      },

    };
  },
  created() {
    this.getData();
  },
  props: {
    // 是否显示弹出层
    show: {
      type: Boolean,
      default: false,
    },
    // 显示弹出层标题
    title: {
      type: String,
      default: "",
    },
  },
  methods: {

    /** 初始化编辑的数据**/
    initData(rowData) {
      this.reset();
      if (rowData && rowData.id) {
        this.form = rowData;
        this.form.datetimerange = [this.form.startTime, this.form.endTime];
      }
    },
    /** 取消按钮 */
    cancel() {
      this.$emit("update:show", false);
      this.reset();
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        classesNumber: undefined,
        classesName: undefined,
        classesCode: undefined,
        professionId: undefined,
        classesGrade: undefined,
        openingTime: undefined,
        orgId: undefined,
        remark: undefined,
      };
      this.resetForm("form");
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (!valid) {
          return;
        }
        // 修改的提交
        if (this.form.id != null) {
          updateClasses(this.form).then((response) => {
            this.$modal.msgSuccess("修改成功");
            this.cancel();
            this.$emit("success");
          });
          return;
        }
        // 添加的提交
        createClasses(this.form).then((response) => {
          this.$modal.msgSuccess("新增成功");
          this.cancel();
          this.$emit("success");
        });
      });
    },
  },
};
</script>
